<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="com.hospital.doctor.doctorh.service.impl.DoctorServiceImpl" %>
<%@ page import="com.hospital.doctor.doctorh.entity.Drugs" %>
<%@ page import="com.hospital.doctor.doctorh.service.DoctorService" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%--
  Created by IntelliJ IDEA.
  User: 29513
  Date: 2021/5/7
  Time: 9:44
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <%
        //获取项目的根路径
        String path = request.getContextPath();
        String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
    %>
    <title>Title</title>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="shortcut icon" href="#"/>
    <script src="<%=basePath%>static/jquery/jquery-1.12.4.js" type="text/javascript"></script>
    <link rel="stylesheet" href="<%=basePath%>static/layui-v2.6.5/layui/css/layui.css">
    <script src="<%=basePath%>static/layui-v2.6.5/layui/layui.js" type="text/javascript"></script>
    <link rel="stylesheet" href="<%=basePath%>static/swee/sweetalert.css">
    <script src="<%=basePath%>static/swee/sweetalert-dev.js"></script>
    <link rel="stylesheet" href="<%=basePath%>static/css/MedicineSelect.css">

    <style type="text/css">

        #back {
            border: 1px solid #0bc9be;
            width: 100px;
            height: 40px;
            display: inline-block;
            background-color: white;
            position: relative;
            right: -1250px;
        }

    </style>
</head>
<body>


<div id="big">

    <button type="button" onclick="window.history.back()" id="back">返回</button>

    <table class="layui-table" lay-skin="line">
        <colgroup>
            <col width="150">
            <col width="150">
            <col width="200">
            <col>
        </colgroup>
        <thead>
        <tr>
            <th>编号</th>
            <th>病人编号</th>
            <th>病人姓名</th>
            <th>医生编号</th>
            <th>问诊时间</th>
            <th>状态</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody id="tbody">
        <c:forEach items="${page.list}" var="pat">
            <tr>
                <td>${pat.getId()}</td>
                <td>${pat.getPatientId()}</td>
                <td>${pat.getPatientName()}</td>
                <td>${pat.getDoctorid()}</td>
                <td>${pat.getTime()}</td>
                <td>问诊中</td>
                <td>
                    <div class="layui-btn-container">
                        <button data-method="offset" data-type="auto" class="layui-btn layui-btn-sm ct"
                                onclick="showCt(${pat.getPatientId()})">查看CT结果
                        </button>
                        <button data-method="offset" data-type="auto" class="layui-btn layui-btn-sm bl"
                                onclick="showHis(${pat.getPatientId()})">查看以往病例
                        </button>
                        <button data-method="offset" data-type="auto" class="layui-btn layui-btn-sm" id="kaiyao">开药
                        </button>
                        <button data-method="offset" data-type="auto" class="layui-btn layui-btn-sm" id="cheneck">去检查
                        </button>
                    </div>
                </td>
            </tr>
        </c:forEach>
        </tbody>
    </table>
</div>
<div style="position: absolute;left: 580px">
    <c:if test="${page.pageNum>page.firstPage}">
        <a href="${pageContext.request.contextPath}/Doctorh/index?start=${page.prePage}">
            <button class="layui-btn layui-btn-primary layui-border-green">上一页</button>
        </a>
    </c:if>
    <span>第${page.pageNum}页/共${page.pages}页(${page.total}条记录)</span>
    <c:if test="${page.pageNum<page.pages}">
        <a href="${pageContext.request.contextPath}/Doctorh/index?start=${page.nextPage}">
            <button class="layui-btn layui-btn-primary layui-border-green">下一页</button>
        </a>
    </c:if>
</div>
<%--CT盒子--%>
<div id="ctDiv" class="layui-bg-gray"
     style="padding: 30px;width: 950px;height: 450px;position: absolute;top: 50px;left: 150px;overflow: auto">
    <div class="layui-btn-container" style="position: absolute;top: 0;left: 905px" id="CtClose">
        <button type="button" class="layui-btn"><i class="layui-icon">X</i></button>
    </div>
    <div class="layui-row layui-col-space15">
        <%--        <div class="layui-col-md6">--%>
        <%--            <div class="layui-panel">--%>
        <div style="padding: 50px 30px;">
            <table class="layui-table" lay-skin="line">
                <colgroup>
                    <col width="150">
                    <col width="150">
                    <col width="200">
                    <col>
                </colgroup>
                <thead style="overflow: auto">
                <tr>
                    <th>编号</th>
                    <th>病人编号</th>
                    <th>病人姓名</th>
                    <th>时间</th>
                    <th>检查项目</th>
                    <th>检查结果</th>
                    <th>医生编号</th>
                </tr>
                </thead>
                <tbody>

                </tbody>
            </table>
        </div>

    </div>
</div>
<%--病例盒子--%>
<div id="DisDiv" class="layui-bg-gray"
     style="padding: 30px;width: 950px;height: 450px;position: absolute;top: 50px;left: 150px;display: none;overflow: auto">
    <div class="layui-btn-container" style="position: absolute;top: 0;left: 905px" id="DisClose">
        <button type="button" class="layui-btn"><i class="layui-icon">X</i></button>
    </div>
    <div class="layui-row layui-col-space15">
        <%--        <div class="layui-col-md6">--%>
        <%--            <div class="layui-panel">--%>
        <div style="padding: 50px 30px;">
            <table class="layui-table" lay-skin="line">
                <colgroup>
                    <col width="150">
                    <col width="150">
                    <col width="200">
                    <col>
                </colgroup>
                <thead style="overflow: auto">
                <tr>
                    <th>病例</th>
                    <th>患病时间</th>
                </tr>
                </thead>
                <tbody>

                </tbody>
            </table>
        </div>
        <%--            </div>--%>
        <%--        </div>--%>
    </div>
</div>

<%--开药盒子--%>
<div class="yaodand"></div>
<div class="yaodan">
    <h1 style="color:#009f95;">华子医院</h1>
    <h3 style="color:#009f95;">门诊处开药</h3>
    <br>
    <form action="">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">诊断号:</label>
                <div class="layui-input-inline">
                    <input type="tel" name="" autocomplete="off" class="layui-input"
                           style="border: none;border-bottom: 1px solid #009f95;" readonly>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">姓名:</label>
                <div class="layui-input-inline">
                    <input type="text" name="" autocomplete="off" class="layui-input"
                           style="border: none;border-bottom: 1px solid #009f95;" readonly>
                </div>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label">医生:</label>
                <div class="layui-input-inline">
                    <input type="tel" name="" autocomplete="off" class="layui-input"
                           style="border: none;border-bottom: 1px solid #009f95;" readonly>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">时间:</label>
                <div class="layui-input-inline">
                    <input type="text" id="myclock" autocomplete="off" class="layui-input"
                           style="border: none;border-bottom: 1px solid #009f95;" readonly>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">诊断结果:</label>
                <div class="layui-input-inline">
                    <input type="text" name="" id="bingli" autocomplete="off" class="layui-input"
                           style=" width:300px ;border: none;border-bottom: 1px solid #009f95;">
                </div>
            </div>
        </div>
    </form>


    <div id="wz" style="background-color: white">
        <div id="test7" class="demo-transfer" style="margin-left: 20px" class="wezhi"></div>
        <div class="layui-btn-container" style="margin-left: 20px" class="wezhi">
            <button type="button" class="layui-btn" lay-demotransferactive="getData" id="suoding">确认药品</button>
            <button type="button" class="layui-btn" lay-demotransferactive="reload" id="sousuo">搜索药品</button>

        </div>
    </div>

    <button type="button" class="layui-btn" id="drugok">确认开药</button>
    <button type="button" class="layui-btn" id="drugno">取消</button>
    <div class="sum">
        <p class="drugdan" style="font-size: 20px">
            药品号<span STYLE="margin-left: 80px;"></span>
            药品名<span STYLE="margin-left: 145px;"></span>
            数量<span STYLE="margin-left: 115px;"></span>
            医嘱</p>
    </div>

</div>
<div class="bccheckqueue"></div>
<div class="checkqueue">
        <span style=" color:#009f95;margin-top: 10px"><h2>华子医院</h2>
        <h3 style="margin-left: 10px">检查项目</h3>
        </span>

    <form class="layui-form" action="" style="background-color: white;">
        <div class="layui-inline">
            <label class="layui-form-label">诊断号:</label>
            <div class="layui-input-inline">
                <input type="tel" name="" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">姓名:</label>
            <div class="layui-input-inline">
                <input type="text" name="" autocomplete="off" class="layui-input">
            </div>
        </div>
        <br><br>

        <label class="layui-form-label">检查项目</label>
        <div class="layui-input-inline">
            <select name="modules" lay-verify="required" lay-search="">
                <option value="0">CT</option>
                <option value="1">和磁共振</option>
                <option value="2">B超</option>
                <option value="3">心电图</option>
                <option value="4">常规检查</option>
            </select>
        </div>
    </form>
    <button data-method="offset" data-type="auto" class="layui-btn layui-btn-sm" id="checkok">确认</button>
    <button data-method="offset" data-type="auto" class="layui-btn layui-btn-sm" id="checkno">取消</button>


</div>

</div>
<script type="text/javascript">
    $("#kaiyao").click(function () {
        $.ajax({
            url: "<%=basePath%>Doctorh/drug",
            type: "post",
            dateType: "json",
            success: function (data) {
                layui.use(['transfer', 'layer', 'util'], function () {
                    var $ = layui.$
                        , transfer = layui.transfer
                        , layer = layui.layer
                        , util = layui.util;
                    //获得数据库所有药的数据
                    //基础效果
                    //实例调用
                    transfer.render({
                        elem: '#test7'
                        , data: data
                        , id: 'key123' //定义唯一索引
                    })
                    //批量办法定事件
                    util.event('lay-demoTransferActive', {
                        getData: function (othis) {

                            getDataa = transfer.getData('key123'); //获取右侧数据

                            $(function () {

                                var count = 0;

                                for (var i in getDataa) {
                                    count++;
                                }

                                for (i = 0; i < count; i++) {
                                    $(".drugdan").after("<p class=" + "xunhuan" + "><span>" +
                                        getDataa[i].value + "</span><span>" + getDataa[i].title + "</span><span></span><input type='text' value='5'>盒" + "" +
                                        " <input type='text' id='yizhu' value='每日3片' style='margin-left: 80px;border: none;border-bottom: 1px solid #e3e2e2 '  ></p>")
                                }

                            })
                        }
                        , reload: function () {
                            //实例重载
                            transfer.reload('key123', {
                                title: ['药库', '开药']
                                , value: []
                                , showSearch: true
                            })
                        }
                    });
                });
            }
        })
    })


</script>
<script type="text/javascript">
    $("#ctDiv").hide();//隐藏CT结果
    $("#DisDiv").hide();//隐藏以往病例
    $("#open").hide();//隐藏开药盒子

    $(function () {
        $(".ct").click(function () {
            $(this).addClass("layui-btn layui-btn-disabled");
            $("#big").css({"opacity": "0.2", "background-color": "#a9a9a9"});
        })
        $(".bl").click(function () {
            $(this).addClass("layui-btn layui-btn-disabled");
            $("#big").css({"opacity": "0.2"});
        })
        $("#CtClose").click(function () {
            $("#ctDiv").hide();
            $(".ct").removeClass("layui-btn-disabled");
            $("#ctDiv tbody").find("tr").remove();
            $("#big").css({"opacity": "1"});
        })
        $("#DisClose").click(function () {
            $("#DisDiv").hide();
            $(".bl").removeClass("layui-btn-disabled");
            $("#DisDiv tbody").find("tr").remove();
            $("#big").css({"opacity": "1"});
        })


        $("#tbody").on("click", "#kaiyao", function () {
            $(".yaodand").show()
            $(".yaodan").show()
            $(".drugdan~p").remove();

            // 获得所有开药框所有的节点
            for (var i = 0, j = 1; i < 4; i++, j++) {

                $(".layui-form-item input:eq(" + i + ")").val($(this).parent().parent().parent().children("td:eq(" + j + ")").text())
            }
            $(".layui-form-item input:eq(3)").val("")

        })
        // 确认开药
        $("#drugok").click(function () {
            //获取 诊断号
            var id = $(".layui-form-item input:eq(0)").val()
            //获取 姓名
            var name = $(".layui-form-item input:eq(1)").val()
            //获取 医生
            var doctorId = $(".layui-form-item input:eq(2)").val();
            //获取 时间
            var time = $(".layui-form-item input:eq(3)").val()
            //得到药品长度
            var len = $(".drugdan~p").length;

            var drugid = new Array();
            var drugsum = new Array();
            var drugtype = new Array();
            //获取节点的药品 数量 医嘱等信息
            var arrlist = $(".drugdan~p")

            for (var i = 0; i < len; i++) {
                drugid[i] = $(arrlist[i]).children("span:eq(0)").text()
                drugsum[i] = $(arrlist[i]).children("input:eq(0)").val()
                drugtype[i] = $(arrlist[i]).children("input:eq(1)").val()
            }
            let strid = drugid.join("-");
            let strsum = drugsum.join("-");
            let strtype = drugtype.join("-");
            $.ajax({
                url: "<%=basePath%>Doctorh/yao",
                type: "post",
                data: {
                    id: id,
                    name: name,
                    doctorId: doctorId,
                    time: time,
                    drugid: strid,
                    drugsum: strsum,
                    drugtype: strtype,
                    bingli: $("#bingli").val()
                },
                dateType: "json",
                success: function (data) {
                    swal("开药成功", "", "success");
                    location.reload();
                }
            })
        })
        $("#drugno").click(function () {
            $(".yaodand").hide()
            $(".yaodan").hide()
            $(".drugdan~p").remove();
        })

        //检查
        $("#tbody").on("click", "#cheneck", function () {
            $(".checkqueue,.bccheckqueue").show()
            $(".checkqueue input:eq(0)").val($(this).parent().parent().parent().children("td:eq(1)").text())
            $(".checkqueue input:eq(1)").val($(this).parent().parent().parent().children("td:eq(2)").text())
        })

        //确定检查
        $("#checkok").click(function () {
            $.ajax({
                url: "<%=basePath%>Doctorh/inspect",//请求路径
                type: "post",//请求方式
                data: {
                    id: $(".checkqueue input:eq(0)").val()
                },//请求参数
                dataType: "json",//数据格式
                success: function (data) {
                    if (data == false) {
                        swal("检查单已开，通知患者去检查")
                        $(".checkqueue,.bccheckqueue").hide()
                    } else {
                        swal("请不要重复开检查单")
                        $(".checkqueue,.bccheckqueue").hide()
                    }
                }
            })
        })

        //关闭
        $("#checkno").click(function () {
            $(".checkqueue,.bccheckqueue").hide()
        })
    })


    function dispttime() {
        var today = new Date();
        var yearr = today.getFullYear();
        var moth = today.getMonth();
        var ri = today.getDate();
        var hh = today.getHours()
        var mm = today.getMinutes()
        var ss = today.getSeconds();
        var sh = "";
        if (hh < 12) {
            sh = "AM"
        } else {
            sh = "PM"
        }
        if (hh > 12) {
            hh = hh - 12
        }

        document.getElementById("myclock").value = yearr + "/" + (moth + 1) + "/" + ri + "/" + hh + ":" + mm + ":" + ss
        9
    }

    setInterval("dispttime()", 1000)

    function showCt(no) {
        let ctNo = no;//获取病人编号,查询ct结果
        // alert(ctNo);
        $.ajax({
            url: "<%=basePath%>/Doctorh/showCt",//请求路径
            type: "get",//请求方式
            data: {
                ctNo: ctNo,
            },//请求参数
            dataType: "json",//数据格式
            success: function (ctList) {
                if (ctList == "false") {
                    swal("该病人没有CT记录");
                    $(".ct").removeClass("layui-btn-disabled");
                    $("#big").css({"opacity": "1"});
                } else {
                    $("#ctDiv").show();
                    console.log(ctList)
                    for (let i = 0; i < ctList.length; i++) {
                        let tr = "<tr> <td>" + ctList[i].id + "</td><td>" + ctList[i].cdiagnoseNo + "</td><td>" + ctList[i].cuserName + "</td><td>" + ctList[i].ctime + "</td><td>" + ctList[i].inspectionItem + "</td><td>" + ctList[i].diagnose + "</td><td>" + ctList[i].doctorid + "</td></tr>";
                        $("#ctDiv tbody").append(tr);
                    }
                }
            }
        })
    }

    function showHis(no) {
        let ctNo = no;//获取病人编号,查询ct结果
        // alert(ctNo);
        $.ajax({
            url: "<%=basePath%>/Doctorh/showHis",//请求路径
            type: "get",//请求方式
            data: {
                ctNo: ctNo
            },//请求参数
            dataType: "json",//数据格式
            success: function (DiList) {
                if (DiList == "false") {
                    swal("该病人没有以往病例");
                    $(".bl").removeClass("layui-btn-disabled");
                    $("#big").css({"opacity": "1"});
                } else {
                    $("#DisDiv").show();
                    for (let i = 0; i < DiList.length; i++) {
                        let tr = "<tr> <td>" + DiList[i].usertype + "</td><td>" + DiList[i].time + "</td></tr>";
                        // alert(tr);
                        $("#DisDiv tbody").append(tr);
                    }
                }
            }
        })
    }


</script>
</body>
</html>
